package com.hzit.controller;

import com.hzit.entity.R;
import com.hzit.entity.Student;
import com.hzit.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
	@Autowired
	private IStudentService studentService;

	//1. 获取所有学生列表
	@GetMapping("/list")
	public R<List<Student>> findAll(){
		List<Student> students = studentService.findAll();
		return R.ok(students);
	}

	//2. 添加学生
	@PostMapping("/add")
	public R add(@RequestBody Student student){
		studentService.add(student);
		return R.ok(null,"添加学生成功!");
	}

	//3. 修改学生
	@PostMapping("/update")
	public R update(@RequestBody Student student){
		studentService.update(student);
		return R.ok(null,"修改学生成功!");
	}

	//4. 根据学生编号删除学生
	@GetMapping("/delete")
	// /student/delete.do?sid=1
	public R delete(@RequestParam(value="sid",required = true) int sid){
		studentService.delete(sid);
		return R.ok(null,"删除学生成功！");
	}
}
